package me.zhengjie.modules.worth.rest;

import me.zhengjie.annotation.Log;
import me.zhengjie.modules.worth.domain.Capital;
import me.zhengjie.modules.worth.service.CapitalService;
import me.zhengjie.modules.worth.service.dto.CapitalDto;
import me.zhengjie.modules.worth.service.dto.CapitalQueryParam;
import org.springframework.data.domain.Pageable;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;
import java.util.Set;

/**
* @author lida
* @date 2022-05-01
**/
@RestController
@RequiredArgsConstructor
@Api(tags = "资产管理管理")
@RequestMapping("/api/capital")
public class CapitalController {

    private final CapitalService capitalService;

    @GetMapping
    @Log("查询资产管理")
    @ApiOperation("查询资产管理")
    @PreAuthorize("@el.check('capital:list')")
    public ResponseEntity query(CapitalQueryParam query, Pageable pageable){
        return new ResponseEntity<>(capitalService.queryAll(query,pageable),HttpStatus.OK);
    }

    @PostMapping
    @Log("新增资产管理")
    @ApiOperation("新增资产管理")
    @PreAuthorize("@el.check('capital:add')")
    public ResponseEntity create(@Validated @RequestBody CapitalDto resources){
        return new ResponseEntity<>(capitalService.insert(resources),HttpStatus.CREATED);
    }

    @PutMapping
    @Log("修改资产管理")
    @ApiOperation("修改资产管理")
    @PreAuthorize("@el.check('capital:edit')")
    public ResponseEntity update(@Validated @RequestBody CapitalDto resources){
        capitalService.updateById(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @DeleteMapping
    @Log("删除资产管理")
    @ApiOperation("删除资产管理")
    @PreAuthorize("@el.check('capital:del')")
    public ResponseEntity delete(@RequestBody Set<String> ids) {
        capitalService.removeByIds(ids);
        return new ResponseEntity<>(HttpStatus.OK);
    }

    /*
    @Log("导出资产管理")
    @ApiOperation("导出资产管理")
    @GetMapping(value = "/download")
    @PreAuthorize("@el.check('capital:list')")
    public void download(HttpServletResponse response, CapitalQueryParam query) throws IOException {
        capitalService.download(capitalService.queryAll(query), response);
    }*/

}
